package com.caigou.controller;

import com.caigou.bean.cms.entity.BusinessCooperation;
import com.caigou.bean.cms.entity.CmsDictionary;
import com.caigou.bean.cms.entity.Feedback;
import com.caigou.bean.cms.entity.SeekReport;
import com.caigou.bean.cms.param.*;
import com.caigou.bean.exam.entity.Users;
import com.caigou.enums.ResponseEnum;
import com.caigou.security.utils.CurrentUser;
import com.caigou.service.IClientsService;
import com.caigou.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/clients")
public class ClientsController {
    @Resource
    private IClientsService clientsService;


    /**
     * 处理商务合作意向
     * @param param
     */
    @PostMapping("/cooperation/handel")
    public Result<Integer> handelCooperationClients(@RequestBody SaveCooperationParam param, @CurrentUser Users user) {
        return clientsService.handelCooperationClients(param,user.getUserid());
    }


    /**
     * 根据条件查询合作意向
     * @param param
     */
    @PostMapping("/cooperation/query")
    @PreAuthorize("hasAnyAuthority('chakanhezuoyixiang')")
    public Result<PageInfo<BusinessCooperation>> queryCooperationClients(@RequestBody CooperationParam param) {

        return clientsService.findCooperationClients(param);
    }


    /**
     * 根据条id查询合作意向详情
     * @param param
     */
    @PostMapping("/cooperation/info")
    @PreAuthorize("hasAnyAuthority('chakanhezuoyixiang')")
    public Result<BusinessCooperation> queryCooperationClient(@RequestBody CooperationParam param) {
        return clientsService.findCooperationClientById(param.getId());
    }



    /**
     * 处理用户寻求报道
     * @param param
     */
    @PostMapping("/report/handel")
    public Result<Integer> handelReportClients(@RequestBody SaveCooperationParam param, @CurrentUser Users user) {
        return clientsService.handelReportClients(param,user.getUserid());
    }


    /**
     * 根据条件查询寻求报道
     * @param param
     */
    @PostMapping("/report/query")
    @PreAuthorize("hasAnyAuthority('chakanbaodaoyaoqing')")
    public Result<PageInfo<SeekReport>> queryReportClients(@RequestBody SeekReportParam param) {
        return clientsService.queryReportClients(param);
    }


    /**
     * 根据条id查询合作意向详情
     * @param param
     */
    @PostMapping("/report/info")
    @PreAuthorize("hasAnyAuthority('chakanbaodaoyaoqing')")
    public Result<SeekReport> queryReportClient(@RequestBody CooperationParam param) {
        return clientsService.queryReportClient(param.getId());
    }


    /**
     * 反馈意见字典表
     * @param
     */
    @PostMapping("/feedback/dic")
    public Result<List<CmsDictionary>> findFeedbackType() {
        return clientsService.findFeedbackType();
    }

    /**
     * 反馈意见添加
     * @param param
     */
    @PostMapping("/feedback/save")
    public Result<Integer> saveFeedback(@RequestBody FeedbackParam param, @CurrentUser Users user) {
        return clientsService.saveFeedback(param,user.getUserid());
    }

    /**
     * 投诉建议后台列表查询
     * @param param
     */
    @PostMapping("/feedback/list/query")
    @PreAuthorize("hasAnyAuthority('chakantousujianyi')")
    public Result<PageInfo<Feedback>> findFeedbackList(@RequestBody FeedbackParam param) {
        if (StringUtils.isEmpty(param.getStartTime()) && StringUtils.isEmpty(param.getEndTime())) {
            param.setTimeFilterType(0);//0代表不传
        }
        if (param.getFeedbackType() == 0) {
            param.setFeedbackType(null);//0代表不传
        }
        if (param.getHandlingStatus() == 2) {
            param.setHandlingStatus(null);//0代表不传
        }

        return clientsService.findFeedbackList(param);
    }

    /**
     * 查询投诉建议详情详情
     * @param param
     */
    @PostMapping("/feedback/detail/query")
    @PreAuthorize("hasAnyAuthority('chakantousujianyi')")
    public Result<Feedback> findFeedbackDetail(@RequestBody FeedbackParam param) {
        return clientsService.findFeedbackDetail(param);
    }

    /**
     * 标记为已处理
     * @param param
     */
    @PostMapping("/feedback/batch/dealWith")
    @PreAuthorize("hasAnyAuthority('tousubianjichulijieguo')")
    public Result<Integer> batchFeedbackDealWith(@RequestBody FeedbackParam param, @CurrentUser Users user) {
        //return clientsService.batchFeedbackDealWith(param.getIds(),user.getUserid());
        return clientsService.feedbackDealWith(param,user.getUserid());
    }

}
